home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / news / misc / arbitron < prev    next >
Encoding:
Text File  |  1991-09-03  |  8.2 KB  |  248 lines

  1. #! /bin/sh
  2. # @(#)arbitron    2.4.4    10/20/89
  3. # arbitron -- this program produces rating sweeps for USENET.
  4. #
  5. # Usage: arbitron
  6. #
  7. # To use this program, edit the "configuration" section below so that the
  8. # information is correct for your site, and then run it. It will produce a
  9. # readership survey for your machine and mail that survey to decwrl.dec.com,
  10. # with a cc to you.
  11. #
  12. # To participate in the international monthly ratings sweeps, 
  13. # run "arbitron" every month. I will run the statistics program on the first
  14. # day of each month; it will include any report that has reached it by that
  15. # time. To make sure your site's data is included, run the survey program no
  16. # later than the 20th day of each month.
  17. #
  18. # Brian Reid, DEC Western Research Lab, reid@decwrl.dec.com
  19. # Updated and bugfixed by 
  20. #    Spencer Thomas, U.of Utah
  21. #    Geoff Kuenning, SAH Consulting
  22. # Updated to work with 2.10.1 and older news systems by
  23. #    Lindsay Cleveland, AT&T Technologies/Bell Labs
  24. # Made to work with 16-bit address spaces by
  25. #    Andy Walker, Maths Dept., University of Nottingham, UK
  26. # Nagging Bourne shell bug fixed by
  27. #    Tom Donahue, Rabbit Software Corp
  28. # Various suggestions provided by:
  29. #    Karl Tombre, CRIN, Vandoeuvre France
  30. #    Dan Kolkowitz, Stanford
  31. #    Paul Eggert, Unisys
  32. # Fixes for YP and NN by
  33. #    Dan Kolkowitz, Stanford
  34. #    Brent Chapman, Capital Market Technology
  35. #
  36. # Note that the results of this program are dependent on the rate at which
  37. # you expire news.  If you are a small site that expires news rapidly, the
  38. # results may indicate fewer active readers than you actually have.
  39. #
  40. ###########################################################################
  41. # Configuration information. Edit this section to reflect your site data. #
  42. TMPDIR=/tmp
  43. NEWS=/usr/lib/news
  44. SPOOL=/usr/spool/news
  45.  
  46. # Make a crude stab at determining the system type. If your installation has
  47. # only one type of system, you can edit out the "if" statement and just turn
  48. # this into an assignment statement of the correct value.
  49. if [ -d /usr/ucb ]
  50. then
  51.     STYPE="bsd"
  52. else
  53.     STYPE="usg"
  54. fi
  55.  
  56. # Range of /etc/passwd UID's that represent actual people (rather than
  57. # maintenance accounts or daemons or whatever)
  58. lowUID=5
  59. highUID=9999
  60.  
  61. # If you aren't running a distributed news system (nntpd & rrn, usually),
  62. # leave NEWSHOST blank. Else set it to the name of the host from which you
  63. # can rcp a copy of the active file.
  64. NEWSHOST=
  65.  
  66. # uucp path: {sun, hplabs, pyramid, decvax, ucbvax}!decwrl!netsurvey
  67. summarypath="netsurvey@decwrl.dec.com $USER"
  68.  
  69.  
  70. # We need to find the uucp name of your host. If this code doesn't work,
  71. # then just put it in literally like this:
  72. #    hostname="decwrl"
  73.  
  74. case $STYPE in
  75.     bsd) cmd='hostname || uuname -l';;
  76.     sysv)cmd='uname -n || uuname -l || hostname';;
  77.     *)   cmd='uuname -l';;
  78. esac;
  79.  
  80. hostname=`sh -c "$cmd" 2>&-`
  81.  
  82. PATH=$NEWS:$PATH
  83. ############################################################################
  84. export PATH
  85. # ---------------------------------------------------------------------------
  86. trap exit 1 2 3 15
  87. trap 's=$?; rm -f $TMPDIR/arb.*.$$; exit $s' 0
  88. set `date`
  89. dat="$2$6"
  90. destination="${MAILER-mail} $summarypath"
  91.  
  92. ################################
  93. # Here are several expressions, each of which figures out approximately how
  94. # many people use this machine. Comment out all but 1 of them; pick the one
  95. # you like best. Initially the most universal but least reliable of them is
  96. # uncommented.
  97. PASSWD=$TMPDIR/arb.passwd.$$
  98. (ypcat passwd || cat /etc/passwd) > $PASSWD
  99.  
  100. # # ###### Scheme #1: fast but usually returns too big a number
  101. nusers=`awk -F: "BEGIN {N=0}\\$3>=$lowUID && \\$3<=$highUID{N=N+1}END{print N}" <$PASSWD`
  102.  
  103. # # ###### Scheme #2 (works with BSD systems)
  104. #nusers=`last | sed '/^wtmp begins/d; s/ .*//; /^$/d' | sort -u | wc -l`
  105.  
  106. # # ###### Scheme #3 (works with USG systems)
  107. #nusers=`who /etc/wtmp | sort -u +0 -1 | wc -l`
  108.  
  109. ################################
  110. #
  111. # Set up awk scripts;  these are too large to pass as arguments on most
  112. # systems.
  113. #
  114. # This awk script generates the actual output report.
  115. # We use 'sed' to substitute in the shell variables to save ourselves
  116. # endless hassle trying to find quoting/backslashing problems.
  117. #
  118. # The input to this script consists of two types of lines (pre-sorted):
  119. #
  120. #    (1) Active-file lines.  These have four fields:  newsgroup name,
  121. #        first existing article, last article number, 'y' or 'n'
  122. #        to allow/disallow posting.
  123. #            mod.mac 00001 00001 y
  124. #
  125. #    (2) .newsrc-derived lines.  These have three fields:  the newsgroup
  126. #        name, the user name and the articles-read information.  The latter
  127. #        can be arbitrarily complex.  It can also be arbitrarily long;
  128. #        this can potentially break either awk or sed, in which
  129. #        case the script will not work.
  130. #            mod.map joe 1-199
  131. #
  132. #    The script uses the type 1 lines to define the newsgroups
  133. #    and their active article ranges.  The .newsrc (type 2) lines are
  134. #    then used to deduce which users are reading that group (a group
  135. #    is being read if the last article seen is in that group's active
  136. #    article range).
  137. #
  138. sed "/^#/d
  139.      s/NUSERS/$nusers/g
  140.      s/HOSTNAME/$hostname/g
  141.      s/DATE/$dat/g" > $TMPDIR/arb.fmt.$$ << 'DOG'
  142. # makereport -- utility for "arbitron". Early versions were copied from a
  143. # similar script distributed with "subscribers.sh" by Blonder, McCreery, and
  144. # Herron.
  145. #
  146.     BEGIN    { rdrcount = 0 ; reader = "" ; grpcount = 0 ; realusers = 0}
  147. #
  148. # Active file line:  dispose of previous group (if any), record group, and
  149. # record first and last article numbers.  Set group's reader count to none.
  150.     NF == 4 { if (grpname != "") {
  151.             printf("%d %s\n",grpcount, grpname)
  152.           }
  153.           grpname = $1
  154.           grpfirst = $3
  155.           grplast = $2
  156.           grpcount = 0
  157.         }
  158. #
  159. # .newsrc line.  Break out the final number, which is the last article that
  160. # has actually been read.  This is a pretty good indicator of the person's
  161. # true interest in the group.  If 'lastread' for the group is a current
  162. # (unexpired) article, record a reader for that group.  Finally, record
  163. # the user as a "real" user of the news system.
  164. #
  165.     NF == 3 { if ($1 != grpname) next;
  166.           n1 = split($3, n2, "-")
  167.           n3 = split(n2[n1], n4, ",")
  168.           lastread = n4[n3]
  169.     if ((grpfirst != grplast) && (lastread >= grpfirst) && (lastread <= grplast)) {
  170.             grpcount++
  171.             if (realuser[$2] != 1) {
  172.                 realuser[$2] = 1
  173.                 realusers++
  174.             }
  175.           }
  176.         }
  177. #
  178. # End of file.  Print the report in 2 columns.
  179.     END    { printf("9999 Host\t\t%s\n","HOSTNAME")
  180.           printf("9998 Users\t\t%d\n",NUSERS)
  181.           printf("9997 NetReaders\t%d\n",realusers)
  182.           printf("9996 ReportDate\t%s\n","DATE")
  183.           printf("9995 SystemType\tnews-arbitron-2.4\n")
  184. # For reorganized network, report a group even if nobody reads it. This will
  185. # help us keep track of where the groups propagate.
  186.           printf("%d %s\n",grpcount, grpname)
  187.         }
  188. DOG
  189.  
  190. cat >$TMPDIR/arb.pwd.$$ <<'MOUSE'
  191. BEGIN    { seen["/"]=1; seen[""] = 1; }
  192.     { if (seen[$6]!=1) {
  193.         printf("if [ -r %s/.nn/rc ] ; then ", $6)
  194.         printf("sed -n '/^+/s/^. \([0-9]*\) \(.*\)/\2 %s \1/p'",$1)
  195.         printf(" <%s/.nn/rc;\n",$6)
  196.         printf("elif [ -r %s/.newsrc ] ; then ", $6)
  197.         printf("sed -n '/: [0-9]/s/:/ %s/p' <%s/.newsrc; fi\n",$1,$6)
  198.         seen[$6]=1;
  199.       }
  200. }
  201. MOUSE
  202.  
  203. # First, make sure we have an active file
  204. if [ -z "$NEWSHOST" ]
  205. then ACTIVE=$NEWS/active
  206. else ACTIVE=/tmp/arb.active.$$
  207.      rcp $NEWSHOST:$NEWS/active $ACTIVE
  208. fi
  209.  
  210. if [ ! -s $ACTIVE ]
  211. then
  212.     echo arbitron: ACTIVE file missing or empty. Cannot continue. >&2
  213.     (exit 1); exit
  214. fi
  215.  
  216. # Next, get the list of .newsrc files with duplicates and unreadable files
  217. # removed.
  218. awk -F: -f $TMPDIR/arb.pwd.$$ <$PASSWD | sh >$TMPDIR/arb.tmp.$$
  219.  
  220. # Check to make sure that we found some
  221. if [ -s $TMPDIR/arb.tmp.$$ ]
  222. then # See if "active" file has 4 fields or only two (pre-2.10.2)
  223.      set `sed 1q < $ACTIVE`
  224.      if [ $# -eq 2 ]
  225.      then egrep  '^[a-z][-0-9_a-z]*\.' $ACTIVE |
  226.       while read group last
  227.       do dir=`echo "$group" | sed 's;\.;/;g'`
  228.          first=`ls $SPOOL/$dir | grep '^[0-9]*' | sort -n | sed 1q`
  229.          case $STYPE in
  230.         usg) echo "$group $last ${first:-$last} X";;
  231.           *) echo "$group $last ${first-$last} X"
  232.          esac
  233.       done
  234.      else egrep '^[a-z][-0-9_a-z]*\.' $ACTIVE
  235.      fi |
  236.      sort - $TMPDIR/arb.tmp.$$ |
  237.      awk -f $TMPDIR/arb.fmt.$$ |
  238.      sort -nr |
  239.      sed '/^$/d
  240.       s/^999[0-9] //' |
  241.      $destination
  242. else echo arbitron: Unable to find any readable .newsrc files >&2
  243.      (exit 1); exit
  244. fi
  245.  
  246.  
  247.  
  248.